<?
	$catstr='';
	$cat2='';
if (isset($_GET['cat'])&&$_GET['cat']) {
	$cat=$_GET['cat'];
	$catstr="where category=$cat";
	$cat2=" category=$cat and ";
}

function getName($id) {
	$sql="select name,parent from  pro_category  where id=$id";
	$r=myQuery($sql);
	if ($id) return getName($r[0][1]).'&gt;'.$r[0][0];
		else return'';
}

if ($catstr) {
	$pos=getName($cat);
}
else $pos='All Products';

if (null==$listfield1) $listfield1 = "code";
if (null==$listfield2) $listfield2 = "name";
if (null==$listfield3) $listfield3 = "category";
if (null==$listfield4) $listfield4 = "mark_new";
if (null==$listfield5) $listfield5 = "publish";
if (null==$listfield6) $listfield6 = "brand";
if (null==$listfield7) $listfield7 = "stock";
if (null==$listfield8) $listfield8 = "auth";

if (null==$ord) $ord=$listfield3;
if (null==$sort) $sort='desc';

if ($sort=='desc') {
	$s='v';
	$as='asc';
}else { 
	$s='^';
	$as='desc';
}

$order=str_replace(',',' '.$sort.',',$ord);
if ($action=="search"){

	$Query = "select id, $listfield1, $listfield2, $listfield3, $listfield4, $listfield5 , $listfield6, $listfield7 , $listfield8 from $table WHERE  $cat2 ( $listfield1 Like '%$Search%' OR $listfield2 Like '%$Search%' OR $listfield6 Like '%$Search%')  order by $order $sort, id desc Limit $Offset, $ListNum";

	$Query1 = "select count(*) as total from $table WHERE $cat2 ( $listfield1 Like '%$Search%' OR $listfield2 Like  '%$Search%' OR $listfield6 Like '%$Search%')";

}else{

	$Query = "select id, $listfield1, $listfield2, $listfield3, $listfield4, $listfield5, $listfield6, $listfield7 , $listfield8  from $table $catstr order by $order $sort, id desc Limit $Offset, $ListNum";

	$Query1 = "select count(*) as total from $table $catstr";
	
}

$list = myQuery($Query);

$CountRecord = myQuery($Query1);

$CountNum = $CountRecord[0][0];
$Url="&Search=$Search&action=$action";
if ($catstr) $Url.="&cat=$cat";


print(splitPage($Url.'&ord='.$ord.'&sort='.$sort,$CountNum));


?>
<script language="javascript">
function openWindow(url,para) {
	window.open (url,"",para);
}
</script>

<b><?=$pos?></b><br>

<form name="form1" method="post" action="../../inc/mod_pub.php">
        <table width="100%" border="0" cellspacing="1" cellpadding="1" class="tb">
          <tr class="tbheader"> 
            <td width="14%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield1.'&sort='.$as?>" class="sort"><?print(ucfirst($listfield1))?></a> <?=(($ord==$listfield1)?$s:'')?></td>
            <td width="23%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield2.'&sort='.$as?>" class="sort"><?print(ucfirst($listfield2))?></a> <?=(($ord==$listfield2)?$s:'')?></td>
            <td width="12%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield7.',code'.'&sort='.$as?>" class="sort">Current Stock</a> <?=(($ord==($listfield7.',code'))?$s:'')?></td>
		    <td width="12%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield5.',code'.'&sort='.$as?>" class="sort"><?print(ucfirst($listfield5))?></a> <?=(($ord==($listfield5.',code'))?$s:'')?></td>
		    <td width="12%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield4.',code'.'&sort='.$as?>" class="sort">New Product</a> <?=(($ord==($listfield4.',code'))?$s:'')?></td>
		    <td width="12%"><a href="<?=$PHP_SELF.'?Start_Num=0'.$Url.'&ord='.$listfield8.',code'.'&sort='.$as?>" class="sort">Promotional</a> <?=(($ord==($listfield8.',code'))?$s:'')?></td>
			<td width="15%"></td>
          </tr>
          <tr class="tbcontent1"> 
            <td></td>
            <td></td>
		    <td></td>
		    <td colspan="3" align=center>
              <input type="submit" name="submit" value="Save">
			  <input type="hidden" name="url" value="../product/info/product_menu.php?Start_Num=<?=$Start_Num.$Url.'&ord='.$ord.'&sort='.$sort?>">
			  <input type="hidden" name="table" value="<?=$table?>">
            </td>
			<td></td>
          </tr>


<?
if ($list){
	for ($i=0;$i<count($list);$i++){?>
          <tr class="tbcontent1"> 
            <td><?print($list[$i][1])?><?if ($list[$i][4]=="1") echo " <font color=red><b>*</b></font>"?></td>
            <td><?print($list[$i][2])?><br><?=$list[$i][6]?></td>
		    <td align=center><?=$list[$i][7]?></td>
		    <td align=center><div align="center">
              <input name="pub[<?=$list[$i][0]?>]" type="radio" id="pub[<?=$list[$i][0]?>]" value="1" <? echo $list[$i][5]?"checked":"";?>> Y <br>
              <input name="pub[<?=$list[$i][0]?>]" type="radio" id="pub[<?=$list[$i][0]?>]" value="0" <? echo !$list[$i][5]?"checked":"";?>> N 
            </div></td>
		    <td align=center><div align="center">
              <input name="new[<?=$list[$i][0]?>]" type="radio" id="new[<?=$list[$i][0]?>]" value="1" <? echo $list[$i][4]?"checked":"";?>> Y <br>
              <input name="new[<?=$list[$i][0]?>]" type="radio" id="new[<?=$list[$i][0]?>]" value="0" <? echo !$list[$i][4]?"checked":"";?>> N 
            </div></td>
		    <td align=center><div align="center">
              <input name="auth[<?=$list[$i][0]?>]" type="radio" id="auth[<?=$list[$i][0]?>]" value="1" <? echo $list[$i][8]?"checked":"";?>> Y <br>
              <input name="auth[<?=$list[$i][0]?>]" type="radio" id="auth[<?=$list[$i][0]?>]" value="0" <? echo !$list[$i][8]?"checked":"";?>> N 
            </div></td>
			<td align=center bgcolor="ECECEC">
			<a href="edit.php?id=<?print($list[$i][0])?>&Start_Num=<?=$Start_Num?>&cat=<?=$cat?>"><img src="<?print($rela_path)?>images/bt_edit.gif" border="0" alt="Edit"></a>
			<a href="delete.php?id=<?print($list[$i][0])?>&Start_Num=<?=$Start_Num?>&cat=<?=$cat?>"><img src="<?print($rela_path)?>images/bt_delete.gif" border="0" Alt="Delete"></a>
			<a href="enquire.php?id=<?print($list[$i][0])?>&Start_Num=<?=$Start_Num?>&cat=<?=$cat?>"><img src="<?print($rela_path)?>images/bt_enquiry.gif" border="0" Alt="Enquire"></a>
			<br><a href="javascript:openWindow('add_stock.php?id=<?print($list[$i][0])?>&Start_Num=<?=$Start_Num?>&cat=<?=$cat?>&even=<?=$action?>&keyword=<?=$Search?>&ord=<?=$ord?>&sort=<?=$sort?>','width=400 height=180');"><img src="<?print($rela_path)?>images/add_stock.gif" alt="Add Stock" border="0"></a>
			<a href="javascript:openWindow('../../inc/trans.php?method=product&search=<?print($list[$i][0])?>','width=700 height=500 scrollbars=yes resizable=yes');"><img src="<?print($rela_path)?>images/transaction.gif" alt="Transactions" border="0" ></a></td>
          </tr>
<?
	}
?>
          <tr class="tbcontent1"> 
            <td></td>
            <td></td>
		    <td></td>
		    <td colspan="2" align=center>
              <input type="submit" name="submit" value="Save">
          </td>
			<td></td>
          </tr>

<?	
}?>


        </table></form>

<?print(splitPage($Url.'&ord='.$ord.'&sort='.$sort,$CountNum))?>
